package cn.stylefeng.guns.modular.recommend.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.recommend.entity.TaoRecommendGoods;
import cn.stylefeng.guns.modular.recommend.mapper.TaoRecommendGoodsMapper;
import cn.stylefeng.guns.modular.recommend.model.params.TaoRecommendGoodsParam;
import cn.stylefeng.guns.modular.recommend.model.result.TaoRecommendGoodsResult;
import  cn.stylefeng.guns.modular.recommend.service.TaoRecommendGoodsService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 推荐商品 服务实现类
 * </p>
 *
 * @author lcw
 * @since 2019-11-18
 */
@Service
public class TaoRecommendGoodsServiceImpl extends ServiceImpl<TaoRecommendGoodsMapper, TaoRecommendGoods> implements TaoRecommendGoodsService {

    @Autowired
    private TaoRecommendGoodsMapper taoRecommendGoodsMapper;

    @Override
    public void add(TaoRecommendGoodsParam param){
        taoRecommendGoodsMapper.addrecommendGoods(param);
    }

    @Override
    public void delete(TaoRecommendGoodsParam param){
        taoRecommendGoodsMapper.deleteByTime(param);
    }

    @Override
    public void update(TaoRecommendGoodsParam param){
        TaoRecommendGoods oldEntity = getOldEntity(param);
        TaoRecommendGoods newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TaoRecommendGoodsResult findBySpec(TaoRecommendGoodsParam param){
        return null;
    }

    @Override
    public List<TaoRecommendGoodsResult> findListBySpec(TaoRecommendGoodsParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TaoRecommendGoodsParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public void addGoods(TaoRecommendGoodsParam param) {
        taoRecommendGoodsMapper.addGoods(param);
    }

    @Override
    public void addrecommendGoods(TaoRecommendGoodsParam paramCondition) {
        taoRecommendGoodsMapper.addrecommendGoods(paramCondition);
    }

    @Override
    public List<TaoRecommendGoodsResult> getIndexGoods(TaoRecommendGoodsParam param) {
        return taoRecommendGoodsMapper.getIndexGoods(param);
    }

    @Override
    public List<TaoRecommendGoodsResult> getGoodsById(TaoRecommendGoodsParam param) {
        return taoRecommendGoodsMapper.getGoodsById(param);
    }

    @Override
    public List<TaoRecommendGoodsResult> getGoodsByType(TaoRecommendGoodsParam param) {
        return taoRecommendGoodsMapper.getGoodsByType(param);
    }

    private Serializable getKey(TaoRecommendGoodsParam param){
        return null;
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TaoRecommendGoods getOldEntity(TaoRecommendGoodsParam param) {
        return this.getById(getKey(param));
    }

    private TaoRecommendGoods getEntity(TaoRecommendGoodsParam param) {
        TaoRecommendGoods entity = new TaoRecommendGoods();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
